package com.test.utils.swing;

import javax.swing.*;
import javax.swing.plaf.FontUIResource;
import java.awt.*;
import java.util.Enumeration;

public class SwingParentFrame extends JFrame {

    private static Container container;

    public SwingParentFrame(String title, Dimension dimension){
        this.setTitle(title);
        this.setSize(dimension);
        this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);
        this.setResizable(false);

        container = this.getContentPane();
        container.setLayout(null);

        this.setDefualtFont();
    }

    public SwingParentFrame() {
    }


    public static Container getContainer() {
        return container;
    }


    private void setDefualtFont() {
        /**设置全局字体**/
        FontUIResource fontUIResource = new FontUIResource(new Font("微软雅黑",Font.PLAIN,14));
        Enumeration<Object> keys = UIManager.getDefaults().keys();
        while(keys.hasMoreElements()){
            Object key = keys.nextElement();
            if(UIManager.get(key) instanceof FontUIResource){
                UIManager.put(key,fontUIResource);
            }
        }
    }
}
